<template>
    <div>
        <base-list ref="yardPlanType" :condition="condition" :datas.sync="yardPlanType" :pageSearch="pageSearch">
            <el-form :inline="true" :model="condition" class="search-form" slot="search" label-width="100px">
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="堆场策划名称">
                            <auto-search-yard-plan-type v-model="condition['search_LIKE_typeName']"></auto-search-yard-plan-type>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="堆场策划类型">
                            <!-- <auto-search-yard-plan-type v-model="condition['search_LIKE_typeCode']"></auto-search-yard-plan-type> -->
                            <el-select v-model="condition['search_EQ_typeCode']" placeholder="请选择" clearable>
                                <el-option v-for="[key, val] in _dictYardPlanType" :key="key" :label="val" :value="key"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="24">
                        <el-button type="primary" icon="el-icon-search" @click="loadData" class="ml-100">查 询</el-button>
                        <el-button formVisible="true" icon="el-icon-plus" @click="handleDialogFormOpen(false)" v-if="power('WJOB_YARDPLAN_PLANTYPE:ADD')">
                            新增
                        </el-button>
                    </el-col>
                </el-row>
            </el-form>
            <el-table slot="list" :data="yardPlanType" border stripe max-height="500">
                <el-table-column prop="typeName" label="堆场策划名称"  min-width="160"></el-table-column>
                <el-table-column prop="typeCode" label="堆场策划类型"  min-width="160">
                    <template slot-scope='scope'>
                        {{ scope.row.typeCode | _filterYardPlanType }}
                    </template>
                </el-table-column>
                <el-table-column prop="orgName" label="所属单位"  min-width="200"></el-table-column>
                <el-table-column prop="deptName" label="所属部门"  min-width="200"></el-table-column>
                <el-table-column fixed="right" align="center" label="操作"  width="140">
                    <template slot-scope="scope">
                        <el-button size="small" type="text" @click="handleDialogFormOpen(true,scope.row)" v-if="power('WJOB_YARDPLAN_PLANTYPE:UPD')">
                            编辑
                        </el-button>
                        <el-button type="text" class="danger" size="small" @click="handleRemove(scope.row)" v-if="power('WJOB_YARDPLAN_PLANTYPE:DEL')">删除
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
        </base-list>
        <yard-plan-type-form ref="yardPlanTypeForm" @load="loadData"></yard-plan-type-form>
    </div>
</template>

<script>
import {
    deleteYardPlanType,
    getYardPlanTypeList
} from "@/api/yardPlan/yardPlan";
import yardPlanTypeForm from "./yardPlanTypeForm";
import autoSearchYardPlanType from "@/components/autocomplete/autoSearchYardPlanType";

export default {
    name: "堆场机械管理",
    components: {
        yardPlanTypeForm,
        autoSearchYardPlanType
    },
    data() {
        return {
            condition: {}, // 查询条件
            yardPlanType: [], // table数组
            pageSearch: getYardPlanTypeList, // 分页查询api接口
            id: ""
        };
    },
    mounted() {
        this.$nextTick(() => {
            this.loadData();
        });
    },
    methods: {
        loadData() {
            this.$refs.yardPlanType.loadData();
        },
        handleDialogFormOpen(bool, item) {
            if (bool) {
                let form = JSON.parse(JSON.stringify(item));
                this.$refs.yardPlanTypeForm.form = {
                    id: form.id,
                    typeCode: form.typeCode,
                    typeName: form.typeName,
                    orgId: form.orgId,
                    orgName: form.orgName,
                    deptId: form.deptId,
                    deptName: form.deptName,
                    containerYardStackPrinciple:
                        form.containerYardStackPrinciple
                };
                this.$refs.yardPlanTypeForm.isEdit = true;
                this.$refs.yardPlanTypeForm.dialogForm = true;
            } else {
                this.$refs.yardPlanTypeForm.dialogForm = true;
            }
        },
        handleRemove(item) {
            this.$confirm(`是否删除该数据?`, "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            })
                .then(() => {
                    deleteYardPlanType(item.id).then(res => {
                        this.$message({
                            type: "success",
                            message: `删除成功!`
                        });
                        this.loadData();
                    });
                })
                .catch(() => {
                    this.$message({
                        type: "info",
                        message: "已取消"
                    });
                });
        }
    }
};
</script>

<style scoped>
</style>
